from django.db import models


# Create your models here.


class GuitarTab(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255, unique=False, default="")
    author = models.CharField(max_length=255, unique=False, default="")
    type = models.IntegerField()
    create_time = models.DateTimeField(auto_now_add=True)
    cover_path = models.TextField()

    def __str__(self):
        return self.name


class GuitarTabImage(models.Model):
    id = models.AutoField(primary_key=True)
    save_path = models.TextField()
    save_name = models.TextField()
    index = models.IntegerField()
    guitar_tab = models.ForeignKey(GuitarTab, related_name='images', on_delete=models.CASCADE)  # 使用ForeignKey代替逻辑外键
    scroll_speed = models.FloatField(default=1.0)  # 滚动速度，默认为1.0
    rollback_to = models.IntegerField(null=True, blank=True)  # 回滚到的index
    rollback_times = models.IntegerField(default=0)  # 回滚次数，默认为0次

    def __str__(self):
        return f"{self.save_name} - {self.index}"
